package examples;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

import com.hyperrealm.kiwi.ui.*;
import com.hyperrealm.kiwi.ui.model.*;
import com.hyperrealm.kiwi.ui.dialog.*;
import com.hyperrealm.kiwi.util.*;

public class DialogTest extends KFrame
{
  public static void main(String args[])
  {
    DialogTest t = new DialogTest();
    t.setVisible(true);
  }

  DialogTest()
  {
    GenericDialog gd = new GenericDialog(this);
    gd.setVisible(true);
    gd.setAlwaysOnTop(true);
    
    JPanel p = getMainContainer();
    p.setBorder(KiwiUtils.defaultBorder);
    setSize(400, 400);

    p.setLayout(new BorderLayout(5, 5));
    p.add("Center", new TitledSeparator("TitledSeparator Example"));

/*    LoginDialog ld = new LoginDialog(KiwiUtils.getPhantomFrame(),
                                     "Please log in.");
                                     ld.setVisible(true); */

//    KiwiUtils.getKiwiAboutFrame().setVisible(true);

    ExceptionDialog ed = new ExceptionDialog(KiwiUtils.getPhantomFrame(),
                                             "Application Error");
    ed.setException("An unexpected error has occurred.", new NullPointerException());
    ed.setVisible(true);
  }

  class GenericDialog extends ComponentDialog implements ActionListener
  {
    private int i = 0;
    private OrderedListModel<Integer> model;
    private JList list;
    private KButton fade_in;
    private KButton fade_out;
    private KPanel p;
    private KPanel pf;
      
    GenericDialog(Frame parent)
    {
      super(parent, "Example", false);
    }


    protected Component buildDialogUI()
    {
      p = new KPanel();
      p.setLayout(new BorderLayout());

      pf = new KPanel();
      pf.setAlpha(0.5f);
      pf.setFadingEnabled(true);
      pf.setLayout(new GridLayout(1, 0));
        
      list = new JList();
      model = new OrderedListModel<Integer>();
      list.setModel(model);

      for(int i = 10; i > 0; i--)
        model.addElement(i);
        
      pf.add(new JScrollPane(list));
        pf.setBorder(KiwiUtils.defaultBorder);

        
      pf.setAlpha(0.5f);

      p.add("Center", pf);

      /*
        KButton br = new KButton("Repeat");
        br.setRepeating(true);
        br.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent evt)
        {
        System.out.println("FIRE!" + (i++));
        }
        });

        p.add("South", br);
      */

      ButtonPanel bp = new ButtonPanel();

      fade_in = new KButton("Fade in");
      fade_in.addActionListener(this);
      bp.addButton(fade_in);

      fade_out = new KButton("Fade out");
      fade_out.addActionListener(this);
      bp.addButton(fade_out);

      p.add("South", bp);
//        p.setAlpha(0.5f);
        
      return(p);
    }

    public void actionPerformed(ActionEvent evt)
    {
      Object o = evt.getSource();

      if(o == fade_in)
        pf.setVisible(true);
      else
        pf.setVisible(false);
    }
  }

    
  
}
